<?
/*****************************************************************************
 * 文件名：Evaluation.php
 * 作用：Evaluation控制器类 负责分词评测系统
 * 创建时间：2010.1.18
 * 作者：赵鹏城
 * ****************************************************************************/
?>

<?php

class Controller_Evaluation extends FLEA_Controller_Action
{
    /*
     * 默认action
     */
    function actionIndex() {
        $word_bank_tdg =& FLEA::getSingleton('Model_TestCase');
        
        /*分页操作*/
        $page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
        $pageSize = 500;
        $conditions = '';
        $sort = 'id ASC';
        FLEA::loadClass('FLEA_Helper_Pager');
        $pager = new FLEA_Helper_Pager($word_bank_tdg, $page, $pageSize,
$conditions, $sort);//&
        $rowset = $pager->findAll(); /*取出$page页数据集*/
        $PagerData = $pager->getPagerData();
        $NavbarIndexs = $pager->getNavbarIndexs($PagerData['currentPage'], 10);

        $pre = -1;
        if(!empty($_POST)) {
            date_default_timezone_set('Asia/Chongqing');
            $score = 0;
            /*foreach的as后用到了key，目的是用key来定位二位数据中的数据，以真正改变数据集中的值*/
            foreach ($rowset as $k=>$row) {
                $rowset[$k]['answer'] = $_POST['answer'.$row['id']];
                $rowset[$k]['result'] = $_POST['result'.$row['id']];
                if (empty($_POST['score'.$row['id']]))
                    $val = 0;
                else 
                    $val = $_POST['score'.$row['id']];
                $score += $val;
            }
            $word_bank_tdg->updateRowset($rowset); /*用数据集更新数据库*/
            
            /*计算准确率precision*/
            $pre = ($score/(count($rowset)*5) * 100);
        }
        
        /*取配置信息*/
        $options_tdg =& FLEA::getSingleton('Model_Options');
        $options_data = $options_tdg->findAll();
        foreach ($options_data as $od) {
            if ($od['option_name'] == 'seg_server_url') {
                $seg_server_url = $od['option_value'];
            }
        }
        if (empty($seg_server_url)) {
            die("seg_server_url option is must!");
        }        
        
        /*使用页数据集rowset显示数据给用户*/
        include("Evaluation.php");
    }
    
    function actionAdd() {
        if (!empty($_POST)) { 
            $id = md5($_POST['case']);
            //echo $_POST['case'];
            //echo $id;
            $id = substr($id, 0, 15);
            //echo $id;
            $row = array(
                'id' => hexdec($id),
                'case' => $_POST['case'],
                'answer' => $_POST['answer'],
            );
            //echo $row['id'];
            $test_case_tdg =& FLEA::getSingleton('Model_TestCase');
            $test_case_tdg->create($row);
        }
        include('AddCase.php');
    }

}

?>
